package org.mspring.platform.counter;

import java.util.Date;
import java.util.concurrent.atomic.AtomicLong;

/**
 * 
 * @since 2014年4月25日
 * @author Gao Youbo
 */
public class CountValue {
    private final AtomicLong count = new AtomicLong();
    private boolean needSync;
    private Date lastUpdateTime; // 最后更新时间
    private Date lastVisitTime; // 最后访问时间（更新+获取）

    public void increment() {
        count.incrementAndGet();
        needSync = true;
        lastUpdateTime = new Date();
        lastVisitTime = new Date();
    }

    public void increment(long delta) {
        count.addAndGet(delta);
        needSync = true;
        lastUpdateTime = new Date();
        lastVisitTime = new Date();
    }

    public long getCount() {
        long countValue = count.get();
        lastVisitTime = new Date();
        return countValue;
    }

    public void setCount(long count) {
        this.count.set(count);
        lastVisitTime = new Date();
    }

    public boolean isNeedSync() {
        return needSync;
    }

    public void setNeedSync(boolean needSync) {
        this.needSync = needSync;
    }

    public Date getLastUpdateTime() {
        return lastUpdateTime;
    }

    public void setLastUpdateTime(Date lastUpdateTime) {
        this.lastUpdateTime = lastUpdateTime;
    }

    public Date getLastVisitTime() {
        return lastVisitTime;
    }

    public void setLastVisitTime(Date lastVisitTime) {
        this.lastVisitTime = lastVisitTime;
    }

}